﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Hotnet.Dal.BaseRepository;
using System.Linq.Expressions;

namespace Hotnet.Biz
{
	public class BaseBiz<TEntity> where TEntity : class
	{
		private IRepository<TEntity> repository;

		public BaseBiz(IRepository<TEntity> repository)
		{
			this.repository = repository;
		}

		public virtual void Insert(TEntity model)
		{
			repository.Insert(model);
		}

		public virtual TEntity[] List()
		{
			return repository.List();
		}

		public virtual void Delete(int id)
		{
			repository.Delete(id);
		}

		//public void UpdateExcludeGenerateKey(TEntity model)
		//{
		//    repository.UpdateExcludeGenerateKey(model);
		//}

		public virtual TEntity Get(int id)
		{
			return repository.Get(id);
		}

		public virtual void Update(TEntity model)
		{
			repository.Update(model);
		}

		public virtual void Update(Expression<Func<TEntity, bool>> filter, Expression<Func<TEntity, TEntity>> evaluator)
		{
			repository.Update(filter, evaluator);
		}

		public virtual void Update(int pkID, Expression<Func<TEntity, TEntity>> evaluator)
		{
			repository.Update(pkID, evaluator);
		}

		public virtual void Update(IQueryable<TEntity> entities, Expression<Func<TEntity, TEntity>> evaluator)
		{
			repository.Update(entities, evaluator);
		}


		public virtual TEntity[] List<TKey>(Expression<Func<TEntity, TKey>> keySelector, bool descending)
		{
			return repository.List<TKey>(keySelector, descending);
		}

	}
}
